<?php

namespace App\Models\Workflow;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Relations\HasMany;

class WorkflowV2OrderNodeModel extends BaseModel
{
    use KfUid;
    use KfSoftDeletes;

    protected $table = 'workflow_v2_order_nodes';

    protected $fillable = [
        'workflowOrderId',
        'pId',
        'nextId',
        'prevId',
        'workflowTemplateNodeId',
        'name',
        'nodeType',
        'businessType',
        'handlerType',
        'cruiseTemplateId',
        'cruiseOrderId',
        'condition',
        'ccInfo',
        'status',
        'isDeleted'
    ];

    const STATUS_WAIT       = 0;
    const STATUS_ING        = 1;
    const STATUS_FINISH     = 2;
    const STATUS_WAIT_CHILD = 3;

    const STATUS_TEXT = [
        self::STATUS_WAIT       => '未开始',
        self::STATUS_ING        => '进行中',
        self::STATUS_FINISH     => '完成',
        self::STATUS_WAIT_CHILD => '等待子节点审批',
    ];

    public function childrenRel(): HasMany
    {
        return $this->hasMany(WorkflowV2OrderNodeModel::class, 'pId', 'id');
    }

    public function orderNodeHandlersRel(): HasMany
    {
        return $this->hasMany(WorkflowV2OrderNodeHandlerModel::class, 'workflowOrderNodeId', 'id');
    }
}
